Skip to content

Fix: calling URLs with curl#780

Open
brenzel wants to merge 4 commits intosipeed:mainfrom
brenzel:patch-3
Open

Fix: calling URLs with curl#780
brenzel wants to merge 4 commits intosipeed:mainfrom
brenzel:patch-3

Conversation

@brenzel
Copy link

@brenzel brenzel commented Feb 25, 2026

📝 Description

Calling URLs via curl results in the error: “Command blocked by safety guard (path outside working dir)”. This commit fixes the problem.

My changes to guardCommand ensure that the command is split into its individual parts (command + options/flags + arguments) and that each part is checked individually. In addition, web URLs are excluded from the check.

🗣️ Type of Change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 📖 Documentation update
  • ⚡ Code refactoring (no functional changes, no api changes)

🤖 AI Code Generation

  • 🤖 Fully AI-generated (100% AI, 0% Human)
  • 🛠️ Mostly AI-generated (AI draft, Human verified/modified)
  • 👨‍💻 Mostly Human-written (Human lead, AI assisted or none)

☑️ Checklist

  • My code/docs follow the style of this project.
  • I have performed a self-review of my own changes.
  • I have updated the documentation accordingly.

Calling URLs via curl results in the error: “Command blocked by safety guard (path outside working dir)”. This commit fixes the problem.
@xiaket xiaket requested a review from lxowalle February 26, 2026 09:37
@xiaket xiaket added type: bug Something isn't working domain: tool labels Feb 26, 2026
Copy link
Collaborator

@yinwm yinwm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review: Fix calling URLs with curl

Thanks for the PR! The fix direction is correct, but I found several issues that need to be addressed before merging.

🔴 Critical Issues

1. Incorrect Command Line Parsing

for _, part := range strings.Split(cmd, " ") {

Splitting by space is incorrect for command-line parsing. It cannot handle quoted arguments:

# This command would be incorrectly split
curl "http://example.com/path with spaces"
# Result: ["curl", "\"http://example.com/path", "with", "spaces\""]

Suggestion: Use shlex or a similar library for proper command-line argument parsing.

2. URL Detection Logic Has a Security Vulnerability

_, err := url.ParseRequestURI(strings.ReplaceAll(part, "\"", ""))
if err == nil {
    continue
}

url.ParseRequestURI accepts relative URIs, which means local paths like /etc/passwd would also parse successfully:

url.ParseRequestURI("/etc/passwd")  // Returns nil error - treated as URL!

This creates a security vulnerability: local paths could be misidentified as URLs and bypass the safety check.

Suggestion: Check if the URL has a scheme and host:

u, err := url.Parse(part)
if err == nil && u.Scheme != "" && u.Host != "" {
    continue  // Real URL, skip path check
}

🟡 Medium Issues

3. Performance: Repeated Calculations Inside Loop

for _, part := range strings.Split(cmd, " ") {
    // ...
    cwdPath, err := filepath.Abs(cwd)  // Called every iteration
    // ...
    pathPattern := regexp.MustCompile(`...`)  // Compiled every iteration

These should be moved outside the loop.

4. Incomplete Quote Handling

strings.ReplaceAll(part, "\"", "")

Only handles double quotes, not single quotes (') which are commonly used on Unix systems.

🟢 Suggested Refactor

The fix approach is correct, but the implementation needs improvement. Here's a suggested refactor:

if t.restrictToWorkspace {
    // Check path traversal on entire command first
    if strings.Contains(cmd, "..\\") || strings.Contains(cmd, "../") {
        return "Command blocked by safety guard (path traversal detected)"
    }

    cwdPath, err := filepath.Abs(cwd)
    if err != nil {
        return ""
    }

    pathPattern := regexp.MustCompile(`[A-Za-z]:\\[^\\\"']+|/[^\s\"']+`)
    matches := pathPattern.FindAllString(cmd, -1)

    for _, raw := range matches {
        // Check if it's a real URL (has scheme and host)
        if u, err := url.Parse(raw); err == nil && u.Scheme != "" && u.Host != "" {
            continue
        }

        p, err := filepath.Abs(raw)
        if err != nil {
            continue
        }

        rel, err := filepath.Rel(cwdPath, p)
        if err != nil {
            continue
        }

        if strings.HasPrefix(rel, "..") {
            return "Command blocked by safety guard (path outside working dir)"
        }
    }
}

Summary

Category Count
🔴 Critical Issues 2
🟡 Medium Issues 2
🟢 Suggestions 1

Verdict: The PR direction is correct, but the implementation has issues - particularly the URL detection logic which could lead to a security vulnerability. Please address these concerns before we can merge this.

fix Incorrect Command Line Parsing
fix URL Detection Logic Has a Security Vulnerability
fix Incomplete Quote Handling
@brenzel
Copy link
Author

brenzel commented Feb 26, 2026

@yinwm I fixed the problems from your review.

@brenzel brenzel requested a review from yinwm February 26, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: tool type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants